#include <stdio.h>
#include <stdlib.h>
struct node
{
    int data;
    struct node *next;
};
struct node *newnode()
{
    struct node *p;
    p = (struct node *)malloc(sizeof(struct node));
    if (p == NULL)
    {
        printf("error\n");
        exit(-1);
    }
    return p;
}
void destroy(struct node *Node)
{
    while (Node != NULL)
    {
        struct node *p = Node->next;
        free(Node);
        Node = p;
    }
}
void print(struct node *Node)
{
    Node = Node->next;
    while (Node != NULL)
    {
        if (Node->next != NULL)
            printf("%d->", Node->data);
        else
            printf("%d", Node->data);
        Node = Node->next;
    }
    printf("\n");
}
void insert(struct node *Node, int x)
{
    struct node *p = newnode();
    p->data = x;
    struct node *q = Node;
    while (q->next != NULL && x > q->next->data)
    {
        q = q->next;
    }
    p->next = q->next;
    q->next = p;
}
void unite(struct node *node1, struct node *node2) / de1为正数链表，node2为负数链表
{
    struct node *p = node2;
    struct node *q = node1;
    struct node *x = newnode();
    //找node2的endposition
    while (p->next != NULL)
    {
        p = p->next;
    }
    p->next = q->next;
}
int main()
{
    struct node *P_node = newnode();
    struct node *N_node = newnode();
    P_node->next = NULL;
    N_node->next = NULL;
    int x;
    while (scanf("%d", &x) != EOF)
    {
        if (x > 0)
        {
            insert(P_node, x);
        }
        else if (x < 0)
        {
            insert(N_node, x);
        }
    }
    print(P_node);
    print(N_node);
    unite(P_node, N_node);
    print(N_node);
    destroy(N_node);
    destroy(P_node);
    return 0;
}
